package com.hushui.mall.commodity.controller;

import com.alibaba.fastjson.TypeReference;
import com.hushui.mall.commodity.dto.SecKillSkuRedisTo;
import com.hushui.mall.commodity.feign.SeckillFeignService;
import com.hushui.mall.commodity.service.SkuInfoService;
import com.hushui.mall.commodity.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.concurrent.ExecutionException;

@Controller
@CrossOrigin//处理跨域问题
public class SkipController {
    @Autowired
    SkuInfoService service;
    @Autowired
    SeckillFeignService seckKillFeignService;

    @RequestMapping("/index")
    public String skipIndex(){
        return "index";
    }

    @RequestMapping("/item")
    public String skipItem(){
        return "item";
    }
    @RequestMapping("/item/{skuId}")
    public String skipItemOne(@PathVariable(value = "skuId")Long skuId, Model model) throws ExecutionException, InterruptedException {
        SkuItemVo item = service.item(skuId);
        model.addAttribute("item",item);
        SecKillSkuRedisTo seckillSkuInfo = seckKillFeignService.getSeckillSkuInfo(skuId).getData("data", new TypeReference<SecKillSkuRedisTo>() {
        });
        model.addAttribute("seckillSkuInfo",seckillSkuInfo);
        return "item";
    }
    @RequestMapping("/list")
    public String List(){
        return "list";
    }
}
